import abc

from pluginlib.plugin import Interface

__all__ = ['NetworkError', 'StatusProviderError', 'StatusProvider']

def load(ctx):
    """Load the plugin."""

    ctx.add_interface(StatusProvider)
    ctx.add_interface(NetworkError)
    ctx.add_interface(StatusProviderError)

class NetworkError(Interface, Exception):
    '''Throwed when there is a connection problem.'''

    def __init__(self, *args, **kwargs):
        Interface.__init__(self)
        Exception.__init__(self, *args, **kwargs)

class StatusProviderError(Interface, Exception):
    '''Throwed when the server returns an error.'''

    def __init__(self, *args, **kwargs):
        Interface.__init__(self)
        Exception.__init__(self, *args, **kwargs)

class StatusProvider(Interface):
    """A provider of statuses."""

    @abc.abstractmethod
    def __init__(self, username, password):
        pass

    @abc.abstractmethod
    def get_new_statuses(self):
        """Poll for new statuses."""
        pass

    @abc.abstractmethod
    def close(self):
        """Close all open resources."""
        pass

